package com.zhongjian.technologycal.mall.net;


import android.content.Context;

import com.zhongjian.technologycal.mall.base.BaseContacts;
import com.zhongjian.technologycal.mall.http.CaheInterceptor;

import com.zhongjian.technologycal.mall.http.MyApiService;
import com.zhongjian.technologycal.mall.http.NovateCookieManger;

import java.io.File;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wei on 2017/11/30.
 */

public class HttpRetrofitClient {

    private static final int DEFAULT_TIMEOUT = 20;
    private MyApiService apiService;
    private static OkHttpClient okHttpClient;
    private static Context mContext;
    private static HttpRetrofitClient sNewInstance;

    private static Retrofit retrofit;
    private Cache cache = null;
    private File httpCacheDirectory;

    public static HttpRetrofitClient getInstance(Context context) {
        if (context != null) {
            mContext = context;
        }
        return new HttpRetrofitClient(context);
    }


    private HttpRetrofitClient(Context context) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addNetworkInterceptor(
                        new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .cookieJar(new NovateCookieManger(context))
                .addNetworkInterceptor(new CaheInterceptor(context))
                .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                .connectionPool(new ConnectionPool(8, 15, TimeUnit.SECONDS))
                // 这里你可以根据自己的机型设置同时连接的个数和时间，我这里8个，和每个保持时间为15s
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BaseContacts.BASE_REQUEST_URL)
                .client(okHttpClient)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())
                .build();
        apiService = retrofit.create(MyApiService.class);

    }


    public Subscription getRequest(String url, Subscriber<ResponseBody> subscriber) {
        return apiService.executeCategoryGet(url)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }


    public Subscription getUrlRequest(int num, Subscriber<ResponseBody> subscriber) {
        return apiService.getHomePage(num)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public Subscription getUrlRequestProductDetails(int productId, Subscriber<ResponseBody> subscriber) {
        return apiService.getProductDetails(productId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public Subscription getUrlRequestMembersArea(int type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getMembersAreaList(type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }


    public Subscription getUrlRequestMembersAreaTag(int tag, int type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getMembersAreaListTag(tag, type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public Subscription postUrlRequest(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultAddressOfUser(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取二级分类商品
    public Subscription getUrlRequestChild(int SubCategoryId, int type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlChild(SubCategoryId, type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取订单数据
    public Subscription getUrlRequestOrderList(String token, String type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlOrderList(token, type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取购物车数据
    public Subscription getUrlRequestCartList(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCartList(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //
    public Subscription getUrlRequestCommit(String token, RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlOrderCommit(token, jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //设置昵称
    public Subscription postUrlRequestNickname(String token, String str, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlNickname(token, str)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //设置推荐人
    public Subscription postUrlRequestInviteCode(String token, String inviteCode, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlInviteCode(token, inviteCode)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取个人中心数据
    public Subscription getUrlRequestCenterData(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCenterData(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取个人中心数据
    public Subscription getUrlRequestAccountBalance(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlAccountBalance(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }


    //升级会员VIP
    public Subscription postUrlRequestLevel(String token, int type, int level, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlVipOrder(token, type, level)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取分流记录
    public Subscription getUrlRequestStreemRecord(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlSplitStreamRecord(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //转让现金币
    public Subscription postUrlRequestOfMoney(String token, Double money, int sysId, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlOfMoney(token, money, sysId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取粉丝列表
    public Subscription getUrlRequestFansList(String token, String type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlFans(token, type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //充值现金币
    public Subscription postUrlRequestOfShipMoney(String token, double money, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlMemberShip(token, money)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //二送一列表
    public Subscription getUrlRequestPresenter(String token, int type, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlPresenter(token, type)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //短信验证码登录
    public Subscription postUrlRequestCodeLogin(RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrldynamicLogin(jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //根据众健号搜索会员
    public Subscription getUrlRequestMemberBySysID(String token, int sysId, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlMemberBySysId(token, sysId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //立即赠送名额
    public Subscription postUrlRequestPresenterPromptly(String token, int passiveUserId, int sendHeadId, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlPresenterPromptly(token, passiveUserId, sendHeadId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //金额明细type =： coupon points vip   elec 红包 购物币  积分  现金币
    public Subscription getUrlRequestAccountBill(String token, String type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlAccountBill(token, type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //更新头像
    public Subscription postUrlRequestUploading(String token, String headphoto, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlUpload(token, headphoto)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //实名认证
    public Subscription postUrlRequestRealName(String token, RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlRealName(token, jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //检查实名认证
    public Subscription getUrlRequestByInfo(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlByInfo(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //申请代理
    public Subscription postUrlRequestApplyProxy(String token, RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlApplyProxy(token, jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //初始化代理申请页面
    public Subscription getUrlRequestProxyApply(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlProxyApply(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取提现账号
    public Subscription getUrlRequestGetAllAccount(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlByGetAllAccount(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //添加支付宝账号
    public Subscription postUrlRequestAddAliAccount(String token, String account, String name, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlAddAliAccount(token, account, name)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //支付宝发起提现请求
    public Subscription postUrlRequestElecMoney(String token, double money, String txType, String cardNo, String tureName, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlElecMoney(token, money, txType, cardNo, tureName)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //银行卡发起提现请求
    public Subscription postUrlRequestBankElecMoney(String token, double money, String txType,
                                                    String cardNo, String tureName,
                                                    String bankName, String bankInfo,
                                                    Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlBankElecMoney(token, money, txType, cardNo, tureName, bankName, bankInfo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //支付密码校验
    public Subscription postUrlRequestPayPassword(String token, String password, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlPayPassword(token, password)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //支付密码设置校验验证码
    public Subscription postUrlRequestPayVerify(RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlVerify(jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //支付密码设置校验验证码
    public Subscription postUrlRequestSettingPayPassword(String paypassword, RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlSettingPayPassword(paypassword, jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //分流
    public Subscription postUrlRequestSplitStream(String token, int toUserId, int type, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlSplitStream(token, toUserId, type)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //会员升级界面初始数据
    public Subscription getUrlRequestEntrance(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlEntrance(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }


    //忘记密码
    public Subscription postUrlRequestForgetPassword(RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlForgetPassword(jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //直接升级
    public Subscription postUrlRequestUpdate(String token, int type, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlUpdate(token, type)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //粉丝数量
    public Subscription getUrlRequestgetFans(String token, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlGetFans(token)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //手机号更换校验验证码
    public Subscription postUrlRequestUpdateUserName(RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlUpdataUserName(jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //手机号更换校验验证码
    public Subscription postUrlRequestUpdateUserNamePhone(String payPasswordCertificate,
                                                          String token,
                                                          String verifyCode,
                                                          String userName,
                                                          Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlUpdataUserNamePhone(payPasswordCertificate, token, verifyCode, userName)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //通过关键字搜索商品
    public Subscription postUrlRequestUpdateUserName(String key, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlSearchProduct(key)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //同步处理子订单支付
    public Subscription postUrlRequestgetPayOrder(String token, String orderNo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlGetHandlePayOrder(token, orderNo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //同步处理父订单支付
    public Subscription postUrlRequestgetPayOrderC(String token, String orderNoC, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlGetHandlePayOrderC(token, orderNoC)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //取消订单
    public Subscription postUrlRequestCancelOrder(String token, String orderNo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlCancelOrder(token, orderNo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取订单详情
    public Subscription getUrlRequestgetOrderDetails(String token, int orderId, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlOrderDetails(token, orderId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //加入购物车
    public Subscription postUrlRequestCartInfo(int productId, int SpecId, String token, int productNum, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlCartInfo(productId, SpecId, token, productNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //投诉建议
    public Subscription postUrlRequestAdvice(String token, String meno, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlAdvice(token, meno)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //购物车具体物品数量更新
    public Subscription postUrlRequestUpdateCartInfoNum(int shoppingCartId, String token, int productNum, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlUpdateCartInfoNum(shoppingCartId, token, productNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);

    }

    //删除购物车数据
    public Subscription postUrlRequestDelShoppingInfo(String token, int shoppingCartId, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlDelShoppingCartInfo(token, shoppingCartId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);

    }

    //申请退款
    public Subscription postUrlRequestApplyRefund(String token, String orderNo, String memo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlApplyRefund(token, orderNo, memo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //申请退货
    public Subscription postUrlRequestApplySaleReturn(String token,
                                                      String orderNo,
                                                      String memo,
                                                      String photo0,
                                                      String photo1,
                                                      String photo2, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlApplySaleReturn(token, orderNo, memo, photo0, photo1, photo2)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //确认收货
    public Subscription postUrlRequestconfirmOrder(String token, String orderNo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlconfirmOrder(token, orderNo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //查看物流
    public Subscription postUrlRequestLogisticsInformation(String token, String orderNo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlLogisticsInformation(token, orderNo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //获取目前支持的银行
    public Subscription getUrlRequestgetAllBank(Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlGetAllBank()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //添加银行卡
    public Subscription postUrlRequestAddBankAccount(String token, String account, String bankName, String bankInfo, String bankLogo, String name,
                                                     Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlAddBankAccount(token, account, bankName, bankInfo, bankLogo, name)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //删除支付宝账号
    public Subscription postUrlRequestDeleteAliAccount(String token, int id, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlDeleteAliAccount(token, id)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //删除银行卡账号
    public Subscription postUrlRequestDeleteBankAccount(String token, int id, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlDeleteBankAccount(token, id)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //删除收货地址
    public Subscription postUrlRequestDeleteAddressById(RequestBody jsonStr, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrldeleteAddressById(jsonStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //现金支付处理vip
    public Subscription postUrlRequestsyncHandleVipOrder(String token, String orderNo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlsyncHandleVipOrder(token, orderNo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    /**
     * ***商学院相关接口***
     */

    //商学院首页
    public Subscription getUrlRequestCommercialcollegeHomePage(Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCommercialcollegeHomePage()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //查看具体课程类型的课
    public Subscription getUrlRequestCommercialcollegeCoursesbytype(int type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCommercialcollegeCoursesbytype(type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //课程详细简介
    public Subscription getUrlRequestCoursedetailbrief(int courseid, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCoursedetailbrief(courseid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //课程详细目录
    public Subscription getUrlRequestCoursedetailcatalog(int courseid, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCoursedetailcatalog(courseid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //课程详细讲师
    public Subscription getUrlRequestCoursedetaillecturer(int courseid, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCoursedetaillecturer(courseid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //课程详细主页
    public Subscription getUrlRequestCoursedetailMain(int courseid, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCoursedetailsMain(courseid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //课程图文详情
    public Subscription getUrlRequestCoursedetailHtml(int courseid, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCoursedetailsHtml(courseid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //我的课程列表
    public Subscription getUrlRequestMyCourse(String token, String type, int page, int pageNum, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlMyCourse(token, type, page, pageNum)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //课程报名
    public Subscription postUrlRequestSignupforcourse(String token, int courseId, double elecnum, double realpay,
                                                      Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlSignupforcourse(token, courseId, elecnum, realpay)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }
    //商学院课程同步支付
    public Subscription postUrlRequestSynchandleordercc(String token, String orderNo, Subscriber<ResponseBody> subscriber) {
        return apiService.postDefaultUrlSynchandleordercc(token, orderNo)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }
    //课程是否已经报名
    public Subscription getUrlRequestCourseissignup(String token, int courseid, Subscriber<ResponseBody> subscriber) {
        return apiService.getDefaultUrlCourseissignup(token, courseid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }
     /**
     * 团购秒杀
     */





}
